home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / lh211src.zip / GETOPT.C < prev    next >
C/C++ Source or Header  |  1991-02-19  |  2KB  |  71 lines

  1. /***********************************************************
  2.     getopt.c -- get options
  3. ***********************************************************/
  4. #include <ctype.h>
  5. #include <stddef.h>
  6. #include <string.h>
  7. #include "lh.h"
  8.  
  9. char    flg_r, flg_p, flg_x, flg_m, flg_a, flg_c, flg_n, flg_t, flg_u,
  10.         flg_v, flg_w, flg_i, flg_h = 1, flg_o, flg_z, flg_l, flg_at;
  11.  
  12. /*******************************
  13.         get options
  14. *******************************/
  15. int getopt(char *p)
  16. {
  17.     static char flg[] = "rpxmacntuvwihozl-";
  18.     static char *flgpos[] = {&flg_r, &flg_p, &flg_x, &flg_m, &flg_a, 
  19.                              &flg_c, &flg_n, &flg_t, &flg_u, &flg_v, 
  20.                              &flg_w, &flg_i, &flg_h, &flg_o, &flg_z,
  21.                              &flg_l, &flg_at};
  22.     static char val[] = "0-1+2";
  23.  
  24.     int i;
  25.     char s;
  26.     char *q;
  27.  
  28.     while ((s = tolower(*p)) != 0) {
  29.         p++;
  30.         q = strchr(flg, s);        /* search switch */
  31.         if (q) {
  32.             i = q - flg;
  33.             if (*p && (q = strchr(val, *p)) != NULL) {
  34.                 *flgpos[i] = (q - val) / 2;
  35.                 p++;
  36.             }
  37. #if 0
  38.               else if (s == 'v' && *p) {
  39.                 if (flg_v == 0)            /* process of '/vSTRING' */
  40.                     flg_v = 1;
  41.                 pager = p;
  42.                 p = "";
  43.             }
  44. #endif
  45.               else if (s == 'z' && *p) {
  46.                 flg_z = 2;                /* process of '/zSTRING' */
  47.                 regext(p);
  48.                 p = "";
  49.             } else if (s == 'w' && *p) {
  50.                 flg_w = 1;                /* process of '/wSTRING' */
  51.                 strcpy(workdir, p);
  52.                 p = "";
  53.             } else {
  54.                 /* flip-flop */
  55.                 *flgpos[i] = !*flgpos[i];
  56.             }
  57.         }
  58. #if 0
  59.           else if (s == 'k') {
  60.             keyword = p;
  61.             p = "";
  62.         }
  63. #endif
  64.           else {
  65.             if (s == '?') usage();
  66.             return 1;
  67.         }
  68.     }
  69.     return 0;
  70. }
  71.